package com.dnjn.happiness.job.api.factory;

import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.common.core.model.SysJobVO;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.job.api.RemoteJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteJobFallbackFactory implements FallbackFactory<RemoteJobService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteJobFallbackFactory.class);
    @Override
    public RemoteJobService create(Throwable throwable) {
        log.error("定时任务服务调用失败: {}" + throwable.getMessage());
        return new RemoteJobService() {
            @Override
            public R<SysJobVO> getInfoById(Long jobId, String source) {
                return R.fail("查询定时任务失败：" + throwable.getMessage());
            }

            @Override
            public R changeStatusApi(SysJobVO sysJobVO, String source) {
                return R.fail("改变定时任务状态失败：" + throwable.getMessage());
            }

            @Override
            public AjaxResult insertJob(SysJobVO sysJobVO, String source) throws Exception {
                return AjaxResult.error("新增定时任务失败：" + throwable.getMessage());
            }

            @Override
            public R updateJob(SysJobVO sysJobVO, String source) throws Exception {
                return R.fail("修改定时任务失败：" + throwable.getMessage());
            }
        };
    }
}
